package com.icoopoo.log.rolling;

import com.icoopoo.log.rolling.sub.ConsoleService;
import com.icoopoo.log.rolling.sub2.ConsoleService2;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.File;

/**
 * @Author : leih
 * @Date : 2020/8/31 13:35
 * @Version : 1.0
 * @Description : TODO
 * @ClassName : ConsoleController
 */

@RestController
@RequestMapping("/console")
@Validated
public class ConsoleController {

    private final static Logger logger = LoggerFactory.getLogger(ConsoleController.class);

    @Autowired
    private ConsoleService consoleService;

    @Autowired
    private ConsoleService2 consoleService2;

    @PostMapping(value = "log")
    public String listAlarm(Integer numLine) {

        if(numLine == null ){
            numLine = 1;
        }
        for (int i = 0 ;i < numLine; i++){
            logger.error("在classpath下寻找是否有logback-test.xml，在classpath下寻找是否有logback.xml");
            logger.warn("在classpath下寻找是否有logback-test.xml，在classpath下寻找是否有logback.xml");
            logger.info("在classpath下寻找是否有logback-test.xml，在classpath下寻找是否有logback.xml");
            logger.debug("在classpath下寻找是否有logback-test.xml，在classpath下寻找是否有logback.xml");
            logger.trace("在classpath下寻找是否有logback-test.xml，在classpath下寻找是否有logback.xml");
        }
        consoleService.logTest(numLine);
        consoleService2.logTest(numLine);

        return "success";
    }

    public static void main(String[] args) {

        File destFile = new File("D:\\upload\\2020\\8\\24");
        File[] allFiles = destFile.listFiles();
        String fileDest = "D:/upload/";
        String fileDest1 = "D:\\upload\\";
        System.out.println(fileDest.length());
        System.out.println(fileDest1.length());

        File ifile = new File("D:\\upload\\2020\\8\\24\\2020082417342280241.jpg");
        for (File item : allFiles ) {

            String filePath = ifile.getAbsolutePath().substring(fileDest1.length());
            System.out.println(filePath);
        }
    }
}
